<?
    final class Principio_Model_CompanyInPoolMapper extends Principio_Model_Company_AbstractMapper
    {
        public static function fetch($id)
        {
            try
            {
                if (intval($id) == -1)
                    return new Principio_Model_CompanyInPool();

                $model_company_in_pool = parent::fetch($id);
                return (is_null($model_company_in_pool) ? new Principio_Model_CompanyInPool() : $model_company_in_pool);
            }
            catch (Exception $ex)
            {
                return self::reportException($ex);
            };
        }


        public static function fetchAll($except_model_company = null, PrincipioLab_IComparator $IComparator = null)
        {
            return Principio_Model_Company_AbstractMapper::fetchByType(Principio_Model_Company::TYPE_COMPANY_IN_POOL, $except_model_company, $IComparator);
        }


        public static function save(Principio_Model_Company_Abstract $model_company_in_pool)
        {
            try
            {
                $data = [
                    'caption' => $model_company_in_pool->getCaption(),
                    'proxy' => $model_company_in_pool->getProxy(),
                    'global_template' => $model_company_in_pool->getGlobalTemplate(),
                    'ext_template' => $model_company_in_pool->getExtTemplate(),
                    'vlan' => "-1",
                    'vlan_pc' => "-1",
                    'default_gw' => "",
                    'netname' => "",
                    'netmask' => "",
                    'broadcast' => "",
                    'range_from' => "",
                    'range_to' => "",
                    'ip' => "",
                    'pool_id' => $model_company_in_pool->getModelPool()->getID(),
                    'type' => Principio_Model_Company::TYPE_COMPANY_IN_POOL
                ];

                if ($model_company_in_pool->getID() == -1)
                    $model_company_in_pool->setID(self::getDBTable()->insert($data));
                else
                    self::getDBTable()->update($data, ['id=?' => $model_company_in_pool->getID()]);

                return true;
            }
            catch (Exception $ex)
            {
                return self::reportException($ex);
            };
        }
    }
?>